import 'package:flutter/material.dart';
import 'dart:async';

import 'package:sunmi_printer/sunmi_printer.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: buildContent(context),
        ),
      ),
    );
  }


  Widget buildContent(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        TextButton(onPressed: () async {
          await SunmiPrinter.printerSelfChecking();
          // await SunmiPrinter.setAlignment(1);
          // await SunmiPrinter.printQRCode(
          //   data: "离离原上草，一岁一枯荣",
          //   modulesize: 6,
          //   errorlevel: 1
          // );
          await SunmiPrinter.printQrCodeImage(
            data: '离离原上草，一岁一枯荣,123123#hellworld',
            width: 250,
            height: 250
          );
          await SunmiPrinter.lineWrap(3);
          await SunmiPrinter.setAlignment(0);
          await SunmiPrinter.printTextWithFont(text: '离离原上草，一岁一枯荣\n', typeface: '', fontsize: 36.0);
          await SunmiPrinter.lineWrap(3);
        }, child: const Text('SelfChecking')),
      ],
    );
  }
}
